-
Notifications
You must be signed in to change notification settings - Fork 502
Add CaseApply optimization
#7421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c8d872c to
47a0318
Compare
47a0318 to
b8810a2
Compare
budget changesplutus-benchmark/bitwise/test/9.6/8
plutus-benchmark/bitwise/test/9.6/Ed25519.golden.eval
plutus-benchmark/cardano-loans/test/9.6/main.golden.eval
plutus-benchmark/coop/test/9.6/authMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/authMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/certMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/certMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/fsMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/fsMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/mustBurnOwnSingleton.golden.eval
plutus-benchmark/linear-vesting/test/9.6/main.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-10.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-100.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-5.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-50.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-10.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-100.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-5.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-50.golden.eval
plutus-benchmark/lists/test/Sum/9.6/left-fold-built-in.golden.eval
plutus-benchmark/lists/test/Sum/9.6/left-fold-data.golden.eval
plutus-benchmark/lists/test/Sum/9.6/left-fold-scott.golden.eval
plutus-benchmark/lists/test/Sum/9.6/right-fold-built-in.golden.eval
plutus-benchmark/lists/test/Sum/9.6/right-fold-data.golden.eval
plutus-benchmark/lists/test/Sum/9.6/right-fold-scott.golden.eval
plutus-benchmark/nofib/test/9.6/clausify-F5.golden.eval
plutus-benchmark/nofib/test/9.6/knights10-4x4.golden.eval
plutus-benchmark/nofib/test/9.6/queens4-bt.golden.eval
plutus-benchmark/nofib/test/9.6/queens5-fc.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-20.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-4.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-20.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-4.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-20.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-4.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-20.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-4.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/sopFwdStakeTrick.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-20.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-4.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-20.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-4.golden.eval
plutus-benchmark/script-contexts/test/V3/Data/9.6/purposeIsWellFormed-4.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq1.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq2.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq3.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq4.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq5.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt1.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt2.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt3.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt4.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt5.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq1.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq2.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq3.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq4.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq5.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt1.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt2.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt3.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt4.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt5.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/mintValueBurned.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/mintValueMinted.golden.eval
plutus-tx-plugin/test/AsData/Budget/9.6/destructSum-manual.golden.eval
plutus-tx-plugin/test/AsData/Budget/9.6/destructSum.golden.eval
plutus-tx-plugin/test/AsData/Budget/9.6/recordFields.golden.eval
plutus-tx-plugin/test/Budget/9.6/constAccL.golden.eval
plutus-tx-plugin/test/Budget/9.6/constElL.golden.eval
plutus-tx-plugin/test/Budget/9.6/findIndexCheap.golden.eval
plutus-tx-plugin/test/Budget/9.6/findIndexEmptyList.golden.eval
plutus-tx-plugin/test/Budget/9.6/findIndexExpensive.golden.eval
plutus-tx-plugin/test/Budget/9.6/map1.golden.eval
plutus-tx-plugin/test/Budget/9.6/map2.golden.eval
plutus-tx-plugin/test/Budget/9.6/map3.golden.eval
plutus-tx-plugin/test/Budget/9.6/show.golden.eval
plutus-tx-plugin/test/Budget/9.6/sumL.golden.eval
plutus-tx-plugin/test/Budget/9.6/sumR.golden.eval
plutus-tx-plugin/test/BuiltinList/Budget/9.6/drop.golden.eval
plutus-tx-plugin/test/BuiltinList/Budget/9.6/take.golden.eval
plutus-tx-plugin/test/BuiltinList/Budget/9.6/uniqueElementJust.golden.eval
plutus-tx-plugin/test/CallTrace/9.6/successfullEvaluationYieldsNoTraceLog.golden.eval
|
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Transform/CaseApply.hs
Outdated
Show resolved
Hide resolved
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Transform/CaseApply.hs
Outdated
Show resolved
Hide resolved
|
I don't understand how this is an optimisation. Can you explain the logic behind it? |
|
You can check here: #7410 (comment) Basically, applying arguments using |
8d79313 to
253835b
Compare
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Simplify.hs
Outdated
Show resolved
Hide resolved
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Transform/CaseApply.hs
Show resolved
Hide resolved
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Transform/CaseApply.hs
Show resolved
Hide resolved
Execution Budget Golden Diffoutputplutus-benchmark/bitwise/test/9.6/8
plutus-benchmark/bitwise/test/9.6/Ed25519.golden.eval
plutus-benchmark/cardano-loans/test/9.6/main.golden.eval
plutus-benchmark/coop/test/9.6/authMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/authMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/certMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/certMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/fsMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/fsMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/mustBurnOwnSingleton.golden.eval
plutus-benchmark/linear-vesting/test/9.6/main.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-10.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-100.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-5.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-builtin-list-50.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-10.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-100.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-5.golden.eval
plutus-benchmark/lists/test/Lookup/9.6/match-scott-list-50.golden.eval
plutus-benchmark/lists/test/Sum/9.6/left-fold-built-in.golden.eval
plutus-benchmark/lists/test/Sum/9.6/left-fold-data.golden.eval
plutus-benchmark/lists/test/Sum/9.6/left-fold-scott.golden.eval
plutus-benchmark/lists/test/Sum/9.6/right-fold-built-in.golden.eval
plutus-benchmark/lists/test/Sum/9.6/right-fold-data.golden.eval
plutus-benchmark/lists/test/Sum/9.6/right-fold-scott.golden.eval
plutus-benchmark/nofib/test/9.6/clausify-F5.golden.eval
plutus-benchmark/nofib/test/9.6/knights10-4x4.golden.eval
plutus-benchmark/nofib/test/9.6/queens4-bt.golden.eval
plutus-benchmark/nofib/test/9.6/queens5-fc.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-20.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-4.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-20.golden.eval
plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-4.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-20.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-4.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-20.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-4.golden.eval
plutus-benchmark/script-contexts/test/V2/9.6/sopFwdStakeTrick.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-20.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-4.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-20.golden.eval
plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-4.golden.eval
plutus-benchmark/script-contexts/test/V3/Data/9.6/purposeIsWellFormed-4.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq1.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq2.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq3.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq4.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/geq5.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt1.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt2.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt3.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt4.golden.eval
plutus-ledger-api/test-plugin/Spec/Budget/9.6/gt5.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq1.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq2.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq3.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq4.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq5.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt1.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt2.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt3.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt4.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt5.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/mintValueBurned.golden.eval
plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/mintValueMinted.golden.eval
plutus-tx-plugin/test/AsData/Budget/9.6/destructSum-manual.golden.eval
plutus-tx-plugin/test/AsData/Budget/9.6/destructSum.golden.eval
plutus-tx-plugin/test/AsData/Budget/9.6/recordFields.golden.eval
plutus-tx-plugin/test/Budget/9.6/constAccL.golden.eval
plutus-tx-plugin/test/Budget/9.6/constElL.golden.eval
plutus-tx-plugin/test/Budget/9.6/findIndexCheap.golden.eval
plutus-tx-plugin/test/Budget/9.6/findIndexEmptyList.golden.eval
plutus-tx-plugin/test/Budget/9.6/findIndexExpensive.golden.eval
plutus-tx-plugin/test/Budget/9.6/map1.golden.eval
plutus-tx-plugin/test/Budget/9.6/map2.golden.eval
plutus-tx-plugin/test/Budget/9.6/map3.golden.eval
plutus-tx-plugin/test/Budget/9.6/show.golden.eval
plutus-tx-plugin/test/Budget/9.6/sumL.golden.eval
plutus-tx-plugin/test/Budget/9.6/sumR.golden.eval
plutus-tx-plugin/test/BuiltinList/Budget/9.6/drop.golden.eval
plutus-tx-plugin/test/BuiltinList/Budget/9.6/take.golden.eval
plutus-tx-plugin/test/BuiltinList/Budget/9.6/uniqueElementJust.golden.eval
plutus-tx-plugin/test/CallTrace/9.6/successfullEvaluationYieldsNoTraceLog.golden.eval
This comment will get updated when changes are made. |
Are there any tests that display this behaviour? I'd actually expect that it would transform into (case (constr 0 (con integer 3) (con integer 2) (con integer 1)) (lam x (lam y (lam z. z)))) |
|
@basetunnel That's a good point. @SeungheonOh your notation is a bit confusing, Jacco is right that based on your notation, where application is parenthesized (in square brackets) to the right, the result wouldn't be correct. But looking at the implementation, it seems to be done fine. Remember, application is left-associative while lambda abstraction is right-associative. I've "mentally executed" the optimization on the following term, and I've applied the reduction semantics specified in the Plutus Core Spec. Looks good. However, I have some issues with the implementation. It's quite hard to read (so many recursive calls in so many places!!!), and it seems to traverse the term many many times so I would expect this optimization to be very computation heavy. If you look at how these optimization functions are called, it's not necessary for each optimization to recurse down the term itself. |
zliu41
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think that you should handle both [(\x . [(\y . t) b]) a] and [[(\x . (\y . t)) a] b], while you are at it. See Note [Multi-beta].
The implementation indeed seems more complex than needed like @ana-pantilie said. It shouldn't need to be much more different than the Beta pass.
| processNestedApp | ||
| :: Term name uni fun a | ||
| -> Term name uni fun a | ||
| processNestedApp (Apply ann body arg) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this not be implemented using transformOf termSubterms, which many other passes use?
Adds "application through case/constr" optimization. Pretty decent free optimizations.
It is also possible to turn programs like
into
But this is only possible when the body of inner lambda doesn't reference variable bounded by all previous lambda abstractions. Maybe this is easier to do on PIR side.